import Vue from "vue";

import XEUtils from 'xe-utils'
import VXEUtils from 'vxe-utils'

Vue.use(VXEUtils, XEUtils)

XEUtils.mixin({
  formatJson(str){
    if (str && str.length > 0) {
      return str.split(",");
    }
    return [];
  },
  toJson(array) {
    if(array && array.length > 0){
      return  array.map(v => v).join(',')
    }
    return ''
  },
  uuid() {
    var s = [];
    var hexDigits = "0123456789abcdef";
    for (var i = 0; i < 36; i++) {
      s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
    s[8] = s[13] = s[18] = s[23] = "-";

    var uuid = s.join("");
    return uuid;
  },
  compareKey (propName,sort) {
    return function (a, b) {
      var val1 = a[propName];
      var val2 = b[propName];
      if(sort && sort=='desc'){
        return val2 - val1;
      }else{
        return val1 - val2;
      }
    }
  },
  isMoney(s) {
    var regu = "^[0-9]+[\.][0-9]{0,3}$";
    var re = new RegExp(regu);
    if (re.test(s)) {
      return true;
    } else {
      return false;
    }
  },
  between(startDate,endDate){
    let day = (endDate - startDate)/(1*24*60*60*1000)
    if(day != 1){
      return day +1
    }else{
      return day
    }
  }
})
